package main

import (
	"fmt"
	"time"
)

// 主线程和协程同时执行的时候,谁快谁慢由系统决定,所以当time.Sleep为0时,会打印no message received
// 如果sleep的时间不为0就可以打印received message

func main() {
	messages := make(chan string)
	msg := "hi"

	go func() {
		messages <- msg
	}()

	// time.Sleep(time.Second)
	time.Sleep(time.Second * 0)
	select {
	case msg2 := <-messages:
		fmt.Println("received message", msg2)
	default:
		fmt.Println("no message received")
	}
}
